package com.niodata.dt.fs;

import java.io.IOException;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

public class LocalFileSystemBuilder implements FileSystemBuilder {

  @Override
  public FileSystem createFileSystem(String user, Map<String, String> conf)
        throws IOException {
    Configuration config = new Configuration();
    String root = conf.get(DpLocalFileSystem.FS_DPLOCAL_ROOT_DIR);
    if (System.getProperty("os.name").toLowerCase().contains("window")) {
      root = root.replace("\\", "/");
    }
    if (!root.startsWith("/")) {
      root = "/" + root;
    }
    config.set(DpLocalFileSystem.FS_DPLOCAL_ROOT_DIR, root);
    config.set("fs.dpLocal.impl",
          DpLocalFileSystem.class.getName());
    config.set("fs.defaultFS", "dpLocal://" + root);
    config.set("io.file.buffer.size", 1024 * 4096 + "");
    FileSystem local = FileSystem.newInstance(config);
    return local;
  }
}
